<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>人物库管理</title>
<link rel="stylesheet" type="text/css"
    href="../../js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
    href="../../js/easyui/themes/icon.css">
<link href="../../js/uploadify/uploadify.css" type="text/css" rel="stylesheet" />   
<script type="text/javascript" src="../../js/easyui/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="../../js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../js/easyui/locale/easyui-lang-zh_CN.js"></script>
<script>

function deletePerson(index) {
	$('#person_grid').datagrid('selectRow', index);
	var node = $('#person_grid').datagrid('getSelected');
	//alert(node.id);
    $('#person_form').form('load', {
        'personForm.id':node.id
    });
    $.messager.confirm('确认','确认要删除吗?',function(fn){   
        if (fn){        	
        	$("#person_form").form('submit', {
                url: "delete_person.action",
                success:function(data) {
                    $('#person_grid').datagrid('reload');
                }
            });   
        }   
    });  
}

function addPerson() {
	window.location.href = "add_person.action";
}

function editPerson(index) {
	$('#person_grid').datagrid('selectRow', index);
	var node = $('#person_grid').datagrid('getSelected');
	window.location.href = "update_person.action?personForm.id=" + node.id;
}

function queryPersons(firstChar) {

    var queryParams = $('#person_grid').datagrid('options').queryParams;
    queryParams.findPattern = "FIRST_CHAR";
    queryParams.firstChar = firstChar;
    $('#person_grid').datagrid('options').queryParams = queryParams;
    //alert($('#galleryGrid').datagrid('options').queryParams[0]);
    $("#person_grid").datagrid('reload');
}
function queryPersonsByName() {

    var queryParams = $('#person_grid').datagrid('options').queryParams;
    queryParams.findPattern = "NAME";
    queryParams.name = $("#name").val();
    $('#person_grid').datagrid('options').queryParams = queryParams;
    //alert($('#galleryGrid').datagrid('options').queryParams[0]);
    $("#person_grid").datagrid('reload');
}

$(function() {
	$('#person_grid').datagrid( {
			url : 'find_persons.action',
			singleSelect : true,
			idField:'id',
			rownumbers:true,
			columns : [ [ 
				//{field: 'id', title: 'ID', width: 80},
				{field: 'name', title: '昵称', width: 250, formatter: function(value, rowData, rowIndex){				 	
				 	var text = " <a target='_blank' href='http://people.fengsung.com/p_" + rowData.id + "/' >" + value +"</a>";
                    return text;
                }},
			 	{field: 'priority', title: '优先级', width: 80},			 	
			 	{field: 'opt', title: '操作', width: 80, formatter: function(value, rowData, rowIndex){				 	
					 	var text = " <a href='#' onclick=\"editPerson(\'" + rowIndex + "\')\"" + ">编辑</a>";
                    <s:if test="1 == #session._user_role_">
                    text = text + " <a href='#' onclick=\"deletePerson(\'" + rowIndex + "\')\"" + ">删除</a>";
                    </s:if>
	                    return text;
	                }}
			] ],
			pagination:true,
			toolbar:[
			            {
			                text:'添加人物',
			                iconCls:'icon-add',
			                handler:function() {
			                    addPerson();
			                }
			            }
			       ]
	});
});
</script>
</head>
<body>
<div id="s" class="easyui-panel" title="名字" icon="icon-search" style="height:80px;padding:10px;">
	<table>
		<tr>
			<td><label>名字:</label></td>
			<td><input name="name" id="name"/></td>
			<td style="width:30px"></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersonsByName()">搜索</a></td>
		</tr>
	</table>
</div>
<div id="p" class="easyui-panel" title="首字母" icon="icon-search" style="height:120px;padding:10px;">
	<table>
		<tr>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('A')">A</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('B')">B</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('C')">C</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('D')">D</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('E')">E</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('F')">F</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('G')">G</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('H')">H</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('I')">I</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('J')">G</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('K')">K</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('L')">L</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('M')">M</a></td>
		</tr>
		<tr>	
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('N')">N</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('O')">O</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('P')">P</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('Q')">Q</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('R')">R</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('S')">S</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('T')">T</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('U')">U</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('V')">V</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('W')">W</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('X')">X</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('Y')">Y</a></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('Z')">Z</a></td>
		</tr>
		<tr>
			<td><a class="easyui-linkbutton" onclick="javascript: queryPersons('others')">其他</a></td>
		</tr>
	</table>
</div>
<table id="person_grid"></table>
<form method="post" id="person_form" name="person_form">
	<input type="hidden" id="personForm.id" name="personForm.id" />
</form>
</body>
</html>